package com.traffic.between.adaptor;

import java.util.Date;

import org.apache.log4j.Logger;

import com.traffic.between.annotation.ChooseProvider;
import com.traffic.between.config.OrderInfoContext;
import com.traffic.between.redis.running.BsmOrderResultExecutor;
import com.traffic.between.service.HanYueServiceImpl;
import com.traffic.managent.service.order.bean.OrderBean;

import net.sf.json.JSONObject;

@ChooseProvider(channel = "hanyue")
public class HanYueAdaptor implements IAdaptor {

	private static Logger log = Logger.getLogger(HanYueAdaptor.class);

	
	public void order() {
	    OrderBean orderBean = OrderInfoContext.getContext();
	    orderBean.setSendTime(new Date());
		String pkgNo = orderBean.getProductCode();//充值的流量套餐编码或话费金额（元）
		String phoneNo = orderBean.getPhoneNo();
		String transNo = orderBean.getIds();//订购流水号
		
		String result = HanYueServiceImpl.service.order(pkgNo, phoneNo, transNo);
		log.info("between-  瀚悦订单HanYueService.order() 订购响应response<>:" + result);
	
		JSONObject json = JSONObject.fromObject(result);           
		String code = json.getString("code");// 只有两个状态 成功或失败

		if ("0".equals(code)) {
			JSONObject item = JSONObject.fromObject(json.getString("item"));
			orderBean.setStatus("7");
			orderBean.setMessage(json.getString("msg"));
			orderBean.setErrorMsg(json.getString("msg"));
		    orderBean.setSuppOrderNo(item.getString("orderId"));
          
		} else {
			orderBean.setStatus("8");
			orderBean.setMessage(json.getString("msg"));
			orderBean.setErrorMsg(json.getString("msg"));
		}
		
		BsmOrderResultExecutor.service.setOrder(orderBean);
	}

}
